# component2/SConscript
Import('env')
import os
with open(env['PROJECT_TOOL_S']) as f:
    exec(f.read())

if 'CONFIG_AX_620E_MSP_ENABLED' in os.environ:
    MSP_PATH = check_wget_down("https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/linux/llm/m5stack_msp.tar.gz", 'm5stack_msp.tar.gz')
    SRCS=[]
    INCLUDE=[]
    PRIVATE_INCLUDE=[]
    REQUIREMENTS=[]
    STATIC_LIB=[]
    DYNAMIC_LIB=[]
    DEFINITIONS=[]
    DEFINITIONS_PRIVATE=['']
    LDFLAGS=[]
    LINK_SEARCH_PATH=[]
    
    env["MSP_PATH"] = MSP_PATH
    INCLUDE += [os.path.join(MSP_PATH, 'out/arm64_glibc/include'), os.path.join(MSP_PATH, 'sample'), os.path.join(MSP_PATH, 'sample/common'), os.path.join(MSP_PATH, 'sample/rtsp')]
    LINK_SEARCH_PATH += [os.path.join(MSP_PATH, 'out/arm64_glibc/lib')]
    REQUIREMENTS += ['dl', 'm', 'pthread']
    third_party = ['drm','faac','fdk-aac','ffmpeg','libsamplerate','mp4','opencv','opus','tinyalsa']
    for dirn in third_party:
        INCLUDE.append(os.path.join(MSP_PATH,'third-party',dirn,'include'))
        LINK_SEARCH_PATH.append(os.path.join(MSP_PATH,'third-party',dirn,'lib/arm64/glibc'))
    INCLUDE.append(os.path.join(MSP_PATH,'third-party/live/out/arm64/glibc/include'))
    LINK_SEARCH_PATH.append(os.path.join(MSP_PATH,'third-party/live/out/arm64/glibc/lib'))
    INCLUDE.append(os.path.join(MSP_PATH,'third-party/openssl/arm64/include'))
    LINK_SEARCH_PATH.append(os.path.join(MSP_PATH,'third-party/openssl/arm64/glibc/lib'))
    LINK_SEARCH_PATH.append(os.path.join(MSP_PATH,'app/lib'))

    env['COMPONENTS'].append({'target':os.path.basename(env['component_dir']),
                            'SRCS':SRCS,
                            'INCLUDE':INCLUDE,
                            'PRIVATE_INCLUDE':PRIVATE_INCLUDE,
                            'REQUIREMENTS':REQUIREMENTS,
                            'STATIC_LIB':STATIC_LIB,
                            'DYNAMIC_LIB':DYNAMIC_LIB,
                            'DEFINITIONS':DEFINITIONS,
                            'DEFINITIONS_PRIVATE':DEFINITIONS_PRIVATE,
                            'LDFLAGS':LDFLAGS,
                            'LINK_SEARCH_PATH':LINK_SEARCH_PATH,
                            'REGISTER':'static'
                            })

